package com.lpc.recyclerview;

import android.content.Context;
import android.support.v7.widget.LinearSmoothScroller;
import android.util.DisplayMetrics;

/**
 * @ Author     ：v_lipengcheng
 * @ Date       ：Created in 14:24 2018/12/22
 * @ Description：平滑的滑动到指定item（网上反映此方案可能会卡）
 */
public class TopSmoothScroller extends LinearSmoothScroller {

    private static final float MILLISECONDS_PER_INCH = 150.0F;//设置滑动屏幕宽高像素所需要的时间

    public TopSmoothScroller(Context context) {
        super(context);
    }

    @Override
    protected int getHorizontalSnapPreference() {
        return SNAP_TO_START;//具体见源码注释
    }
    @Override
    protected int getVerticalSnapPreference() {
        return SNAP_TO_START;//具体见源码注释
    }

    @Override
    protected float calculateSpeedPerPixel(DisplayMetrics displayMetrics) {
        return MILLISECONDS_PER_INCH / (float)displayMetrics.densityDpi;
    }
}
